﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMPLib;

namespace demo03
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        IWMPPlaylistCollection playlistcol;
        IWMPPlaylistArray playlistarray;
        int iCount;

        private void ShowPlayList()
        {
            playlistcol = axWindowsMediaPlayer1.playlistCollection;
            playlistarray = playlistcol.getAll();
            iCount = playlistarray.count;

            listBox1.BeginUpdate();
            for (int i = 0; i < iCount; i++)
            {
                listBox1.Items.Add(playlistarray.Item(i).name);
            }
            listBox1.EndUpdate();
            listBox1.SelectedIndex = 0;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ShowPlayList();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            listBox3.Items.Clear();
            IWMPPlaylist playlist = playlistarray.Item(listBox1.SelectedIndex);
            string strAttr = "";
            string strItemNames = "";
            int iAttribCount = 0;
            iAttribCount = playlist.attributeCount;
            for (int j = 0; j < iAttribCount; j++)
            {
                strAttr = playlist.get_attributeName(j) + " -- ";
                strAttr += playlist.getItemInfo(playlist.get_attributeName(j));
                listBox2.Items.Add(strAttr);
            }
            for (int j = 0; j < playlist.count; j++ )
            {
                strItemNames = playlist.get_Item(j).name;
                listBox3.Items.Add(strItemNames);
            }
            axWindowsMediaPlayer1.currentPlaylist = playlist;
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }
    }
}
